package com.sx.controller;

import com.sx.service.SaleBillService;
import com.sx.service.serviceImpl.SaleBillServiceImpl;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.IOException;
import java.io.Serial;

@WebServlet("/checkSaleBillIDExists.action")
public class checkSaleBillIDExists extends HttpServlet {
    @Serial
    private static final long serialVersionUID = 1L;
    private final SaleBillService saleBillService = new SaleBillServiceImpl();
    private final Logger logger = LogManager.getLogger(checkSaleBillIDExists.class);

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=UTF-8");
        String SaleBillID = req.getParameter("id");
        logger.info("输入的SaleBillID:{}", SaleBillID);
        if (saleBillService.checkSaleBillIDExists(SaleBillID)) {
            resp.getWriter().write("true");
        } else {
            resp.getWriter().write("false");
        }
    }
}
